#include<16f877a.h>
//#device ADC=10
#include<stdio.h>

#fuses HS,NOWDT,NOPROTECT,NOLVP
#use delay(clock=16000000)
#use rs232(baud=9600, xmit=PIN_C6, rcv=PIN_C7)

#define row1() init_lcd(0x80)	/* Begin at Line 1 */
#define row2() init_lcd(0xC0)   /* Begin at Line 2 */
#define LCD_Clear() init_lcd(0x01)	/* Clear display LCD */
unsigned char w[] = { 0x38,0x0c,0x01,0x06,0x80};
char val;
static int a=32;
int i,c=0;

#define HIGH 1
#define LOW 0
#define MOT1 PIN_C0
#define MOT2 PIN_C1
#define MOT3 PIN_C2
#define MOT4 PIN_C3
#BYTE RCREG = 0x1A
/*void forward()
 {
output_bit(MOT1,HIGH);
output_bit(MOT2,LOW);
output_bit(MOT3,LOW);
output_bit(MOT4,HIGH);
 }*/

#INT_RDA
void SerialDataReceive()
{
	if(RCREG=='a')
   {// Store the received data byte by byte
	c++;}

}
/*======================================================LCD Initialisation============================================*/
void init_lcd(unsigned char j)
{
   output_e (0x00);
   output_d (j);
   output_e (0x02);
   delay_ms (2);
   output_e (0x00);
   delay_ms (2);
}
/*=======================================================Display Function=============================================*/
void display(char s)
{
   output_e (0x01);
   output_d (s);
   output_e (0x03);
   delay_ms (2);
   output_e (0x01);
   delay_ms (2);
}
/*=======================================================Functions For ROW============================================*/
void Lcd_init()
{
unsigned char i=0;
   for( i = 0 ; i < 6 ; i++ )
   {
      init_lcd (w[i]);
   }
}
void transmit()
{
for(i=0;i<5;i++)
   {
      putchar('b');
   delay_ms(1000);
   }
}
void receive()
{
   val=getchar();
   delay_ms(100);
   if(val=='a')
   {
   row2();
   display("Another Crane");
   delay_ms(5000);
   }
}
void main()
{

int dum1,dummy,b;
enable_interrupts(INT_RDA);
   enable_interrupts(GLOBAL);
   //printf("crane");
   Lcd_init();
   row1();
   display("Crane Control");
   while(1)
   {
   /*for(i=0;i<10;i++)
   {
   val[i]=getch();
   delay_ms(100);
   }*/
   if(c>0)
   {
   row2();
   display("Another Crane");
   delay_ms(5000);
   c=0;
   }
   
   row2();
   display("Wind: ");
   delay_ms(100);
   display(".");
   
   a=a+5;
   
   a=a+9;
   a=a-5;
   a=a-3;
   a=a+6;
   a=a+4;
   a=a-9;
   a=a+3;
   a=a-10;
   a=a-3;
   a=a+8;
   
   if(a>=52)
   {
   a=30+3;
   }
   dum1=a;
   b=a;
         b=dum1%100;
         b=b/10;
         dummy=b+48;
         display(dummy);
         //transmit(dummy);
         delay_us(10);
         b=dum1%10;
         dummy=b+48;
         //transmit(dummy);
         display(dummy);
         delay_ms(10);
         display("KPH");
   
     a=a+5;
   
   a=a-9;
   a=a+5;
   a=a+3;
   a=a-6;
   a=a+4;
   a=a+9;
   a=a+3;
   a=a-10;
   a=a+3;
   a=a-8;
   //a=320;
   transmit();
  }
}

